package com.durian.ui.adapter.multi;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.collection.ArrayMap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

/**
 * 说明：MultiItemViewProvider
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2017/12/15 9:55
 * <p/>
 * 版本：version 1.0
 */
public abstract class MultiItemViewProvider<C> extends ViewProvider<C> {

    private ArrayMap<String, ViewProvider> mViewProviders = new ArrayMap<>();

    @NonNull
    @Override
    protected MultiItemViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return null;
    }

    @Override
    protected final void convert(@NonNull MultiItemViewHolder holder, @NonNull C item, int position) {

    }

    @Override
    protected final View getItemView(Context context) {
        return super.getItemView(context);
    }

    @Override
    protected final int getItemLayoutId() {
        return 0;
    }

    @Override
    public boolean isMultiType() {
        return true;
    }

    @Override
    protected ArrayList<ViewProvider> getAllMultiViewProviders() {
        ArrayList<ViewProvider> providers = new ArrayList<>();
        for (String key:mViewProviders.keySet()){
            providers.add(mViewProviders.get(key));
        }
        return providers;
    }

    public final MultiItemViewProvider<C> with(ViewProvider<C>... providers) {
        if (providers != null && providers.length > 0) {
            for (ViewProvider<C> provider : providers) {
                if (provider != null) {
                    mViewProviders.put(provider.getClass().getCanonicalName(), provider);
                }
            }
        }
        return this;
    }

}